using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;using THSERP.BusinessEntities;using THSERP.BaseProvider;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using THSLib;using THSERP.BaseProvider;

namespace THSERP.Modules.CompanyConstant
{
    public partial class guiConfigValue : THSERPScreen
    {
        private const string ADConfigValue = "ADConfigValue";

        DataTable tblConfigValue ;
        public guiConfigValue()
        {
            InitializeComponent();
        }

   

        private void guiConfigValue_Load(object sender, EventArgs e)
        {
            tblConfigValue = ADConfigValueUtility.glbdsConfigValues.Tables[ADConfigValueUtility.ADConfigValueAll];
            fld_dgcADConfigValues.DataSource = tblConfigValue;
        }

        //public void SaveConfigValues()
        //{
        //    foreach (DataRow row in tblConfigValue.Rows)
        //    {
        //        String strKey = row["Value"].ToString();
        //        String strText = row["Text"].ToString();
        //        if (!String.IsNullOrEmpty(strKey))
        //        {
        //            ADConfigValueUtility.UpdateValueToADConfigValueTable(strKey, strText);
        //        }
        //    }
        //    ADConfigValueUtility.InitGlobalConfigValueTables();
        //}

        public void SaveConfigValues()
        {
            ADConfigValuesController objADConfigValuesController = new ADConfigValuesController();
            DataSet dsADConfigValues = objADConfigValuesController.GetAllObjects();
            if (dsADConfigValues.Tables[0].Rows.Count == tblConfigValue.Rows.Count)
            {
                for (int i = 0; i < dsADConfigValues.Tables[0].Rows.Count; i++)
                {
                    ADConfigValuesInfo objADConfigValuesInfo = (ADConfigValuesInfo)objADConfigValuesController.GetObjectFromDataRow(dsADConfigValues.Tables[0].Rows[i]);
                    String strKey = tblConfigValue.Rows[i]["Value"].ToString();
                    String strText = tblConfigValue.Rows[i]["Text"].ToString();
                    objADConfigValuesInfo.ADConfigKey = strKey;
                    objADConfigValuesInfo.ADConfigText = strText;

                    objADConfigValuesController.UpdateObject(objADConfigValuesInfo);
                }
            }

            ADConfigValueUtility.InitGlobalConfigValueTables();
        }

        private void fld_btnContactType_Click(object sender, EventArgs e)
        {
            guiConfigContactType _guiConfigContactType = new guiConfigContactType();
            _guiConfigContactType.Module = this.Module;
            _guiConfigContactType.ShowDialog();
        }

        private void fld_btnCustomerType_Click_1(object sender, EventArgs e)
        {
            guiConfigCustomerType _guiConfigCustomerType = new guiConfigCustomerType();
            _guiConfigCustomerType.ShowDialog();
        }

        private void fld_btnInvoiceType_Click(object sender, EventArgs e)
        {
            guiConfigCustomerInvoiceType _guiConfigCustomerInvoiceType = new guiConfigCustomerInvoiceType();
            _guiConfigCustomerInvoiceType.ShowDialog();
        }

        private void fld_btnOrderType_Click(object sender, EventArgs e)
        {
            guiConfigCustomerOrderType _guiConfigCustomerOrderType = new guiConfigCustomerOrderType();
            _guiConfigCustomerOrderType.ShowDialog();
        }

        private void fld_btnProductType_Click(object sender, EventArgs e)
        {
            guiConfigProductType _guiConfigProductType = new guiConfigProductType();
            _guiConfigProductType.ShowDialog();
        }

        private void fld_btnPaymentMethod_Click(object sender, EventArgs e)
        {
            guiConfigPaymentMethod _guiConfigPaymentMethod = new guiConfigPaymentMethod();
            _guiConfigPaymentMethod.ShowDialog();
        }

        private void fld_btnSave_Click(object sender, EventArgs e)
        {
            //fld_dgvADConfigValues
            SaveConfigValues();
            MessageBox.Show("Restart System to get effect!", 
                "#Message#", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        
        
    }
}